<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="../file/images/dianmin.png" rel="shortcut icon" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="../file/css/gwc.css"/>

<title>我的订单</title>

</head>
<body>
	<div class="top">
		<img src="../file/images/dianmin.png" width="300px" height="100px" >
		<div class="header-info">
			<div class="login-info" id="login_info">
				<!--用户-->
			</div>
			<div class="person-info">
				<span>|</span>
				<a href="../index.html" >返回首页</a>
				<span>|</span>
				<a href="./perInfo.html">个人信息</a>
				<span>|</span>
				<a onclick="exitLogin()" style="cursor: pointer">退出登录</a>
			</div>
		</div>
	</div>
	
	<table width="95%" border="1" cellspacing="" cellpadding="5" >
		<thead>
			<tr >
				<th>订单编号</th>
				<th>订单用户</th>
				<th>订单商品</th>
				<th>订单总价（元）</th>
				<th>创建时间</th>
			</tr>
		</thead>
		<tbody id="orderBody">

		</tbody>
	</table>
	</body>
<script src="../file/js/jquery-3.4.1.min.js" type="text/javascript"></script>
<script src="../file/js/jquery-ui.min.js" type="text/javascript"></script>
<script src="../file/js/slide.js" type="text/javascript"></script>

<script>
	$(function () {
		ifLogin();
		showAll();
	})

	function ifLogin() {
		//开始发送请求 验证用户是否登录
		$.ajax({
			url: "/ifLogined",
			type: "POST",
			success: function (data) {
				console.log(data);
				let str = '';
				if (data.code == 200) {
					str += '<a href="../loginPage.html" title="您好！请登录">您好！请登录</a>';
					str += '<a href="../reg.html" title="免费注册">免费注册</a>';
					// location.href="loginPage.html";
					// return;
				} else {
					str += '<a href="user/perInfo.html"> 【' + data.memberinfo.nickname + '】</a>';
				}
				//放入进去上面空的地方
				$(".login-info").html(str);
			}
		})
	};
	function exitLogin() {
		$.ajax({
			url: "/exitLogin" ,
			type: "GET",
			success: function () {
				location.href="../index.html";
			}
		})
	};

	function showAll() {
		$.ajax({
			url: "/user/showAllOrders",
			type: "GET",
			success: function (data) {
				console.log(data);

				// console.log(data[0].shopNames[0])
				let str = '';
				let j=0;
				for (let i = 0; i < data.length; i++) {

					var date = data[i].date;
					/*转化时间*/
					var date1 = new Date(date);
					var date2=(date1.toLocaleDateString().replace(/\//g, "-") + " " + date1.toTimeString().substr(0, 8));



					str +=	`<tr>
								<td align="center" width="100" id="td1">${data[i].oid}</td>
								<td align="center" width="100" id="td2">${data[i].nickname}</td>

								<td align="center" width="120" id="td3">商品：${data[i].shopNames}
								<br/> 数量：${data[i].shopNums}</td>

								<td align="center" width="100" id="td4">${data[i].totalprice}</td>
								<td align="center" width="100" id="td5">${date2}</td>
							</tr>`;
				}
				$("#orderBody").html(str);

			}
		})
	};

</script>
</html>